package com.yinhai.redis.cluster.event.filter;

import com.yinhai.redis.cluster.event.Event;

public class EventTypeFilter implements EventFilter{

	private Class<?> eventType;
	
	public EventTypeFilter(Class<?> eventType) {
		this.eventType = eventType;
	}

	@Override
	public boolean match(Event event) {
		if(event==null) return false;
		return eventType==event.getClass();
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((eventType == null) ? 0 : eventType.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		EventTypeFilter other = (EventTypeFilter) obj;
		if (eventType == null) {
			if (other.eventType != null)
				return false;
		} else if (!eventType.equals(other.eventType))
			return false;
		return true;
	}

}
